package com.tuozixuan.javafx.shape;


import javafx.application.Application;
import javafx.scene.Cursor;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.paint.Color;
import javafx.scene.shape.Line;
import javafx.scene.shape.StrokeLineCap;
import javafx.scene.shape.StrokeLineJoin;
import javafx.scene.shape.StrokeType;
import javafx.stage.Stage;

public class LineDemo extends Application {
	
    public static void main(String[] args) {
        launch(args);
    }

	@Override
	public void start(Stage primaryStage) throws Exception {
		
		Line line1 = new Line(201,201, 201,250);
		
		Line line = new Line();
		line.setStartX(100);
		line.setStartY(100);
		line.setEndX(200);
		line.setEndY(200);
		
		// True表示打开反锯齿，false表示关闭反锯齿。
		line.setSmooth(true);
		
		
		// 设置形状的笔划线的颜色
		line.setStroke(Color.RED);
		// 设置线的宽度
		line.setStrokeWidth(2);
		// 设置在Shape节点的边界周围绘制描边的位置
		line.setStrokeType(StrokeType.INSIDE);
		line.setStrokeType(StrokeType.OUTSIDE);
		line.setStrokeType(StrokeType.CENTERED);
		
		// 在线或路径的末尾设置帽样式
		line.setStrokeLineCap(StrokeLineCap.BUTT);
		line.setStrokeLineCap(StrokeLineCap.ROUND);
		line.setStrokeLineCap(StrokeLineCap.SQUARE);
		
		// 当线相遇时设置装饰
		line.setStrokeLineJoin(StrokeLineJoin.MITER);
		line.setStrokeLineJoin(StrokeLineJoin.ROUND);
		line.setStrokeLineJoin(StrokeLineJoin.BEVEL);
		
		//line.getStrokeDashArray().addAll(15d, 5d, 15d, 15d, 20d);
		line.getStrokeDashArray().addAll(2d, 2d, 2d, 2d, 2d);
		line.setStrokeDashOffset(10);
		
		//line.setFill(Color.BLUE);
		
		// 设置当鼠标悬停在线条上时鼠标指针的显示
		line.cursorProperty().set(Cursor.HAND);
		
        Scene scene = new Scene(new Group(line, line1), 300, 300);

        // 设置左上角图标
        primaryStage.getIcons().add(new Image("see.png"));
        primaryStage.getIcons().addAll(new Image("see.png"), new Image("see.png"));
        
        // 设置标题
        primaryStage.setTitle("Welcome to JavaFX!");
        
        primaryStage.setScene(scene);
        primaryStage.sizeToScene();
        primaryStage.show();
        
        // 隐藏窗体
        primaryStage.hide();
        primaryStage.show();
        
        // 关闭窗口，相当于点击窗口关闭图标
        //primaryStage.close();
	}

}
